
//
//  GQHFreightModel.m
//  Xanthium
//
//  Created by GuanQinghao on 23/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHFreightModel.h"


@implementation GQHFreightModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {

    return @{
             @"qh_freightID" : @[@"id",@"sourceId"],
             @"qh_departureID" : @"origin",
             @"qh_departure" : @"origin",
             @"qh_departureLatitude" : @"originLatitude",
             @"qh_departureLongitude" : @"originLongitude",
             @"qh_destinationLatitude" : @"destinationLatitude",
             @"qh_destinationLongitude" : @"destinationLongitude",
             @"qh_destinationID" : @"destination",
             @"qh_destination" : @"destination",
             @"qh_mileage" : @"mileage",
             
             @"qh_freightName" : @"commodityName",
             @"qh_freightType" : @"goodsType",
             @"qh_freightTypeCode" : @"goodsType",
             @"qh_modelWanted" : @"demandVehicleLength",
             @"qh_lengthWanted" : @"demandModels",
             @"qh_note" : @"note",
             
             @"qh_freightWeight" : @"demandVehicle",
             @"qh_freightVolume" : @"goodsVolume",
             @"qh_freightNumber" : @"goodsNum",
             @"qh_freightUnitPrice" : @"freightUnitPrice",
             @"qh_freightWeightRemained" : @"remainVehicle",
             
             @"qh_loader" : @"loader",
             @"qh_loaderMobile" : @"loaderPhone",
             @"qh_loadingTime" : @"loadingTime",
             
             @"qh_posterID" : @"releasePeople",
             @"qh_enterpriseName" : @"comName",
             @"qh_posterAvatar" : @"headImg",
             @"qh_posterName" : @"releasePeopleName",
             @"qh_posterType" : @"releasePeopleType",
             @"qh_posterTypeCode" : @"releasePeopleType",
             @"qh_posterMobile" : @"releasePeoplePhone",
             @"qh_posterScore" : @"score",
             @"qh_postTime" : @"releaseTime",
             @"qh_state" : @"releaseState",
             
             @"qh_followed" : @"friend",
             @"qh_quotationCount" : @"quotationNum",
             @"qh_agreementCount" : @"agreementNum",
             @"qh_pushOrNot" : @"pushOrNo",
             @"qh_offerStatus" : @"offerStatus"
             };
}


/**
 "origin": "长治市 襄垣县",
 "destination": "本溪市 本溪满族自治县",
 "demandModels": "平板挂车",
 "demandVehicleLength": "5.2米",
 "loadingTime": "2018-05-19 14:53:21",
 "pushOrNo": "02",
 "commodityName": "asdasdas",
 "sourceId": "40284774636bffe801636ce009560077"
 */

///  获取货源列表
+ (void)qh_fetchFreightsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHFreightModel *> *freights))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buSources/1/list"];
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *freightArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHFreightModel *freightModel = [GQHFreightModel yy_modelWithDictionary:object];
                if (freightModel) {
                    
                    [freightArray addObject:freightModel];
                }
            }
            success(YES,code,message,freightArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
